$(document).ready(function() {
	var VIEW_AS_ADMIN = $("#view-as-admin");
	var VIEW_AS_STUDENT = $("#view-as-student");

	VIEW_AS_ADMIN.on('click', function() {
		sendViewRequest("admin");
	});

	VIEW_AS_STUDENT.on('click', function() {
		sendViewRequest("student");
	});

	function sendViewRequest(view_as) {
		$.ajax({
			type: 'POST',
			url: '/view-as/',
			data: {'view-as': view_as},
			dataType: 'html',
			success: ajaxSuccess,
			error: ajaxError
		});
	}

	function ajaxSuccess(response) {
		location.reload();
	}

	function ajaxError(response) {
		console.log("Ajax post returned error when switching 'view as'")
	}
});